<template>
				<view class="icons" @click.stop="like">
					<uni-icons color="#dd524d" size="20" :type="likes?'star-filled':'star'"></uni-icons>
				</view>
</template>

<script>
	export default {
		data() {
			return {
				likes: false
			};
		},
		props:{
			item:{
				type:Object,
				default: {},
			}
		},
		watch:{
			item(newVal){
				this.likes = this.item.is_like
			}
		},
		created() {
		},
		onLoad() {
		},
		mounted() {
			this.likes = this.item.is_like
		},
		methods:{
			like(){
				this.likes = !this.likes
				this.get_updata_like()
				// console.log("收藏了");
			},
			async get_updata_like(){
				uni.showLoading()
				const res = await this.$api.get_updata_like({
					user_id: '60c2d733f6a3980001d73348',
					article_id:this.item._id
				})
				uni.showToast({
					title:this.likes?"收藏成功":"取消收藏",
					icon:"none"
				})
				uni.$emit('updataLike')
				uni.hideLoading()
			}
		}
	}
</script>

<style scoped lang="scss">
	.icons{
		position: absolute;
		right: 0;
		top: 0;
		height: 20px;
		width: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
		.uni-icons{
			color: $uni-color-error;
		}
	}
</style>
